package org.example.erp.controller;

import org.example.erp.domain.Warehouse;
import org.example.erp.service.impl.WarehouseServiceImpl;
import org.example.erp.service.impl.WorkshopServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class WarehouseContrller {
    @Autowired
    WarehouseServiceImpl warehouseService;

    @GetMapping("/warehouseSettings/find")
    public DataResult find(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
                           @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                           @RequestParam (required = false)String warehouseCode,
                           @RequestParam (required = false)String warehouseName){
        return DataResult.success(warehouseService.findwarehouse(currentPage,pageSize,warehouseCode,warehouseName));
    }


    @PostMapping("/warehouseSettings/insert")
    public  DataResult insert(@RequestBody Warehouse warehouse){
        return DataResult.success( warehouseService.save(warehouse));
    }

    @PutMapping("/warehouseSettings/update")
    public DataResult update(@RequestBody Warehouse warehouse){
        return DataResult.success(warehouseService.updateById(warehouse));
    }

    @DeleteMapping("/warehouseSettings/delete")
    public DataResult datele(@RequestBody List<Integer> logIds){
        return DataResult.success(warehouseService.removeByIds(logIds));
    }


   @GetMapping("/warehouseSettings/findlist")
    public DataResult find2(){
        return DataResult.success(warehouseService.findwarehousearea());
   }



}
